#!/bin/bash
TOMCAT_USER=${TOMCAT_USER}
TOMCAT_PWD=${TOMCAT_PWD}
if [ -e /scripts/firstrun ]; then
echo '<tomcat-users>'>${CATALINA_HOME}/conf/tomcat-users.xml
echo '<role rolename="manager-gui"/>' >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo '<role rolename="manager-script"/>' >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo '<role rolename="manager-jmx"/>' >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo '<role rolename="admin-gui"/>' >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo '<role rolename="admin-script"/>' >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo "<user username=\"${TOMCAT_USER}\" password=\"${TOMCAT_PWD}\" roles=\"manager-gui,manager-script,manager-jmx,admin-gui, admin-script\"/>" >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo '</tomcat-users>' >> ${CATALINA_HOME}/conf/tomcat-users.xml 
rm  /scripts/firstrun
wget -P ${CATALINA_HOME}/lib http://central.maven.org/maven2/org/springframework/spring-instrument-tomcat/4.1.1.RELEASE/spring-instrument-tomcat-4.1.1.RELEASE.jar
mv ${CATALINA_HOME}/webapps/ROOT ${CATALINA_HOME}/webapps/welcome
fi

if [ ! -e ${CATALINA_HOME}/logs/catalina.out  ]; then
  echo ''>${CATALINA_HOME}/logs/catalina.out
fi

if [ ! -e ${CATALINA_HOME}/keep  ]; then
  echo 'This is the keep file.'>${CATALINA_HOME}/keep
fi

${CATALINA_HOME}/bin/catalina.sh start

tail -f ${CATALINA_HOME}/keep
